home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_tut / nextdate.ada < prev    next >
Text File  |  1996-01-30  |  2KB  |  52 lines

  1. with Text_IO; use Text_IO;
  2. procedure Nextdate is
  3.    type Month_Type is
  4.       (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
  5.    subtype Day_Subtype is Integer range 1 .. 31;
  6.    type Date is
  7.       record
  8.          Day   : Day_Subtype;
  9.          Month : Month_Type;
  10.          Year  : Positive;
  11.       end record;
  12.    Passed : Boolean := True;
  13.    function Tomorrow(Today : in Date) return Date is separate;
  14.  
  15.    procedure Display (S : in String; D : in Date) is
  16.       package Int_IO is new Integer_IO(Integer); use Int_IO;
  17.    begin
  18.       Put(S);
  19.       Put(D.Day, Width => 3);
  20.       Put(" " & Month_Type'Image(D.Month));
  21.       Put(D.Year, Width => 5);
  22.       New_Line;
  23.    end Display;
  24.    procedure Compare(Today, Right_Answer : in Date) is
  25.       My_Answer : Date := Tomorrow(Today);
  26.    begin
  27.       if My_Answer /= Right_Answer then
  28.          Display("Today:       ", Today);
  29.          Display("My answer:   ", My_Answer);
  30.          Display("Right answer:", Right_Answer);
  31.          New_Line;
  32.          Passed := False;
  33.       end if;
  34.    end Compare;
  35. begin
  36.    Compare((12,Dec,1815), (13,Dec,1815)); -- ordinary date
  37.    Compare(( 3,Feb,1986), ( 4,Feb,1986)); -- ordinary date in Feb.
  38.    Compare((30,Jun,1981), ( 1,Jul,1981)); -- last day of 30-day month
  39.    Compare((30,Sep,3999), ( 1,Oct,3999)); -- last day of 30-day month
  40.    Compare((31,Mar,1876), ( 1,Apr,1876)); -- last day of 31-day month
  41.    Compare((31,Aug,1984), ( 1,Sep,1984)); -- last day of 31-day month
  42.    Compare((31,Dec,1966), ( 1,Jan,1967)); -- last day of year
  43.    Compare((28,Feb,1980), (29,Feb,1980)); -- leap year
  44.    Compare((28,Feb,1600), (29,Feb,1600)); -- century leap year
  45.    Compare((28,Feb,2200), ( 1,Mar,2200)); -- century non-leap year
  46.    Compare((28,Feb,1982), ( 1,Mar,1982)); -- non-leap year
  47.    Compare((29,Feb,1980), ( 1,Mar,1980)); -- leap day in leap year
  48.    if Passed then
  49.       Put_Line("Congratulations, you completed the assignment!");
  50.    end if;
  51. end Nextdate;
  52.